//
//  HLMessageCell.m
//  zhuanxian
//
//  Created by qipai on 2017/11/30.
//  Copyright © 2017年 huiling. All rights reserved.
//

#import "HLMessageCell.h"

@interface HLMessageCell()

@property(nonatomic,strong)UILabel* labelTime;
@property(nonatomic,strong)UILabel* labelContent;

@end

@implementation HLMessageCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        UIImageView* backView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"hl_message_back"]];
        backView.contentMode = UIViewContentModeScaleToFill;
        backView.image = [backView.image resizableImageWithCapInsets:UIEdgeInsetsMake(backView.image.size.height*0.4, backView.image.size.width*0.4, backView.image.size.height*0.4, backView.image.size.width*0.4) resizingMode:UIImageResizingModeStretch];
        [self.contentView addSubview:backView];
        [backView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.left.right.mas_equalTo(5);
        }];
        
        UILabel* label = [UILabel new];
        label.textColor = UIColorFromRGB(0xB5B5B6);
        label.font = [UIFont systemFontOfSize:16];
        label.text = @"消息通知";
        [backView addSubview:label];
        [label mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(20);
            make.top.mas_equalTo(20);
        }];
        
        [backView addSubview:self.labelTime];
        [self.labelTime mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.mas_equalTo(-20);
            make.centerY.mas_equalTo(label);
        }];
        
        [backView addSubview:self.labelContent];
        [self.labelContent mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(label);
            make.right.mas_equalTo(self.labelTime);
            make.top.mas_equalTo(label.mas_bottom).offset(16);
        }];
        
        [backView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.mas_equalTo(self.labelContent.mas_bottom).offset(20);
            make.bottom.mas_equalTo(self.contentView.mas_bottom).offset(-7);
        }];
    }
    return self;
}

- (void)setMessageObject:(HLMessageObject *)messageObject {
    _messageObject = messageObject;
    self.labelTime.text = messageObject.createDate;
    self.labelContent.text = messageObject.content;
}

- (UILabel*)labelTime {
    if (!_labelTime) {
        _labelTime = [UILabel new];
        _labelTime.textAlignment = NSTextAlignmentRight;
        _labelTime.textColor = UIColorFromRGB(0xB5B5B6);
        _labelTime.font = [UIFont systemFontOfSize:12];
    }
    return _labelTime;
}

- (UILabel*)labelContent {
    if (!_labelContent) {
        _labelContent = [UILabel new];
        _labelContent.textColor = UIColorFromRGB(0x6a7078);
        _labelContent.font = [UIFont systemFontOfSize:15];
        _labelContent.numberOfLines = 0;
    }
    return _labelContent;
}

@end
